package com.ruoyi.background.service.impl;

import com.ruoyi.background.domain.AppGuestbook;
import com.ruoyi.background.mapper.AppGuestbookMapper;
import com.ruoyi.background.service.IAppGuestbookService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 用户留言Service业务层处理
 *
 * @author susu
 * @date 2024-08-26
 */
@Service
public class AppGuestbookServiceImpl implements IAppGuestbookService {
    @Autowired
    private AppGuestbookMapper appGuestbookMapper;

    /**
     * 查询用户留言
     *
     * @param id 用户留言主键
     * @return 用户留言
     */
    @Override
    public AppGuestbook selectAppGuestbookById(Long id) {
        return appGuestbookMapper.selectAppGuestbookById(id);
    }

    /**
     * 查询用户留言列表
     *
     * @param appGuestbook 用户留言
     * @return 用户留言
     */
    @Override
    public List<AppGuestbook> selectAppGuestbookList(AppGuestbook appGuestbook) {
        return appGuestbookMapper.selectAppGuestbookList(appGuestbook);
    }

    /**
     * 新增用户留言
     *
     * @param appGuestbook 用户留言
     * @return 结果
     */
    @Override
    public int insertAppGuestbook(AppGuestbook appGuestbook) {
        appGuestbook.setCreateTime(DateUtils.getNowDate());
        appGuestbook.setCreateBy(SecurityUtils.getUsername());
        appGuestbook.setUpdateTime(DateUtils.getNowDate());
        appGuestbook.setUpdateBy(SecurityUtils.getUsername());
        return appGuestbookMapper.insertAppGuestbook(appGuestbook);
    }

    /**
     * 修改用户留言
     *
     * @param appGuestbook 用户留言
     * @return 结果
     */
    @Override
    public int updateAppGuestbook(AppGuestbook appGuestbook) {
        AppGuestbook appGuestbook1 = appGuestbookMapper.selectAppGuestbookById(appGuestbook.getId());
        if (ObjectUtils.isEmpty(appGuestbook1)) throw new RuntimeException("对象不存在！");
        appGuestbook.setUpdateTime(DateUtils.getNowDate());
        appGuestbook.setUpdateBy(SecurityUtils.getUsername());
        return appGuestbookMapper.updateAppGuestbook(appGuestbook);
    }

    /**
     * 批量删除用户留言
     *
     * @param ids 需要删除的用户留言主键
     * @return 结果
     */
    @Override
    public int deleteAppGuestbookByIds(Long[] ids) {
        return appGuestbookMapper.deleteAppGuestbookByIds(ids);
    }

    /**
     * 删除用户留言信息
     *
     * @param id 用户留言主键
     * @return 结果
     */
    @Override
    public int deleteAppGuestbookById(Long id) {
        return appGuestbookMapper.deleteAppGuestbookById(id);
    }
}
